package com.ycg.vue.modules.system.controller;

import com.ycg.vue.Entity.HomeImagesEntity;
import com.ycg.vue.result.Result;
import com.ycg.vue.modules.system.service.SystemService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Description 系统管理
 * @Author jink
 * @Date 2024/2/15 18:16
 */
@RestController
@RequestMapping("/system")
public class SystemController {

    @Resource
    private JavaMailSender mailSender;

    @Resource
    private SystemService systemService;

    @Resource
    private RedisTemplate<String,Object> redisTemplate;

    @GetMapping("/checkToken/{finderPrint}")
    public Result checkToken(@PathVariable String finderPrint){
        return systemService.checkToken(finderPrint);
    }

    @GetMapping("/pageHomeImages")
    public Result pageHomeImages() {
        return systemService.pageHomeImages();
    }

    @RequestMapping("/uploadHomepage")
    public Result upload(@RequestParam("file") MultipartFile file) {
        return systemService.upload(file);
    }

    @PostMapping("/homeImageList")
    public Result homeImageList(@RequestBody HomeImagesEntity homeImages) {
        return systemService.homeImageList(homeImages);
    }

    @PostMapping("/changeHomeImage")
    public Result changeHomeImage(@RequestBody Map<String, String> map) {
        return systemService.changeHomeImage(map);
    }

    @GetMapping("/selectTypeByCode")
    public Result selectTypeByCode(String type) {
        return systemService.selectTypeByCode(type);
    }

    @RequestMapping("/picUpload")
    public Result picUpload(@RequestParam("file") MultipartFile file) {
        return systemService.picUpload(file);
    }

    @GetMapping("/sendMail/{email}")
    public Result sendMail(@PathVariable("email") String email) {
        return systemService.sendMail(email);
    }

    @GetMapping("/logout/{fingerPrint}")
    public Result logout(@PathVariable String fingerPrint){
        redisTemplate.delete(fingerPrint);
        return  Result.success();
    }
}
